//package com.example.gc.webredisgc.config;
//
//import com.example.gc.webredisgc.TenantDataSourceManager;
//import org.springframework.lang.Nullable;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * @author sjw
// * @className WebControllerConfigurerAdapter
// * @date 2021/9/19 10:53
// * @description: TODO
// */
//@Component
//public class WebControllerConfigurerAdapter implements WebMvcConfigurer {
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new HandlerInterceptor() {
//            @Override
//            public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//                String tenant = request.getHeader("tenant");
//                if (tenant == null) TenantDataSourceManager.setTenantId(0);
//                else {
//                    TenantDataSourceManager.setTenantId(Integer.parseInt(tenant));
//                    DynamicDataSourceUtil.setContextHolder(tenant);
//                }
//                return true;
//            }
//            @Override
//            public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception{
//                TenantDataSourceManager.removeTenantId();
//                DynamicDataSourceUtil.removeContextHolder();
//            }
//        }).addPathPatterns("/**");
//    }
//}
